package com.example.springboot.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

/**
 * WebSocket的配置
 */
@Configuration
@EnableWebSocketMessageBroker//开启使用STOMP协议来传输基于代理的消息
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {//注册STOMP的节点（endpoint）,并映射制定的URL
        registry.addEndpoint("/endpointWisely").withSockJS();//注册一个STOMP的endpoint，并制定使用ScokJS协议
        registry.addEndpoint("endpointChat").withSockJS();//注册一个名为endpointChat的endpoint
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {//配置消息代理（Message Broker）
        //registry.enableSimpleBroker("/topic"); //广播式应配置一个/topic消息代理
        registry.enableSimpleBroker("/queue","/topic");//点对点式应增加一个/queue的消息代理
    }
}
